<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的钱包-维多购物平台</title>
    <link rel="shortcut icon" href="./images/favicon.ico" type="image/x-icon" />
    <link href="./bootstrap-3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/style.css">
    <script src="./js/jquery-3.4.1.min.js"></script>
    <script src="./bootstrap-3.4.1/js/bootstrap.min.js"></script>
    <script src="./js/index.js" type="module" defer="defer"></script>
    <script src="./js/cookie.js"></script>
    <style>
        header {
            background-color: rgba(0,0,0,.7);;
            backdrop-filter: blur(20px);
        }

        main {
            padding: 10px;
        }

        .wallet-center {
            width: 100%;
            margin: 60px 0 50px 0;
            max-width: 1200px;
        }

        .wallet-center-content {
            display: flex;
            background-color: var(--color-background);
            border-radius: 3px;
            padding: 20px;
            justify-content: space-between;
        }

        .wallet-center-content span {
            font-size: 40px;
            font-weight: 900;
            color: var(--ui-colors-orange);
        }

        h2 {
            font-size: 25px;
            font-weight: 600;
            margin-bottom: 20px;
        }

        h4 {
            font-size: 16px;
            font-weight: 600;
        }

        .wallet-record {
            width: 100%;
            padding: 20px;
            display: flex;
            flex-direction: column;
            background-color: var(--color-background);
            border-radius: 3px;
            margin-bottom: 40px;
            max-width: 1200px;
        }

        .wallet-record table {
            width: 100%;
            border-top: 2px solid var(--ui-colors-neutral5);
        }

        .wallet-record thead {
            background-color: var(--ui-colors-neutral5);
        }

        .wallet-record tbody {
            width: 100%;
        }

        .wallet-record table tr {
            width: 100%;
            border-bottom: 2px solid var(--ui-colors-neutral5);
        }

        .wallet-record table .type {
            width: 80px;
        }

        .wallet-record table .time,
        .wallet-record table .money {
            width: 190px;
        }

        .wallet-record table .money span {
            font-size: 10px;
            color: var(--ui-colors-neutral9);
        }

        .wallet-record table .money h4 {
            margin: 2px;
            color: var(--ui-colors-orange);
        }

        .wallet-center p {
            width: 100px;
            height: 30px;
            margin: 0;
            border-radius: 3px;
            align-items: center;
            justify-content: center;
            border: 2px solid #ff5c00b0;
            background-color: #ff5c0085;
            display: flex;
            column-gap: 3px;
            cursor: pointer;
            color: #fff;
            fill: #fff;
        }

        .wallet-center p:hover {
            background-color: #ff5c00b0;
        }

        .wallet-center a {
            color: var(--ui-colors-neutral9);
            fill: var(--ui-colors-neutral9);
            display: flex;
            column-gap: 3px;
            cursor: pointer;
        }

        .wallet-center a:hover {
            color: var(--ui-colors-orange);
            fill: var(--ui-colors-orange);
        }

        .modal-body {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .modal-content {
            background-color: var(--color-background-soft);
            padding: 0 10px 10px 10px;
        }

        .modal-content .title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 2px solid var(--ui-colors-neutral5);
        }

        .modal-btn-close {
            background-color: var(--color-none);
            border: none;
            font-size: 30px;
        }

        .modal-content form {
            max-width: 270px;
            display: flex;
            gap: 10px;
            margin: 10px 0;
            flex-flow: wrap;
        }

        .modal-content form .form-line {
            display: flex;
            align-items: center;
        }

        .modal-content .content form .radio {
            display: none;
        }

        .modal-content .content form label {
            width: 60px;
            height: 30px;
        }

        .modal-content .content form span {
            width: 100%;
            height: 100%;
            border: 2px solid #ff5c00b0;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 3px;
            color: var(--ui-colors-neutral11);
        }

        .modal-content .content form input:checked ~ span {
            background-color: #ff5c0085;
        }

        .modal-content .content form label.priceDiy {
            width: 130px;
        }

        .modal-content .content form label.priceDiy input {
            width: 100%;
            height: 100%;
        }

        .modal-content .operate {
            display: flex;
            justify-content: flex-end;
            column-gap: 10px;
        }

        .modal-content .operate .btn-primary {
            background-color: var(--ui-colors-orange);
        }

        .modal-content button:focus {
            display: none;
        }
    </style>
</head>

<body>
    <header id="header" class="has-user">
        <div class="logo">
            <img src="./images/logo.png" alt="logo">
        </div>
        <nav class="main-menu">
            <a href="/">首页</a>
            <a href="/allphone">手机</a>
            <a href="/allcomputer">电脑</a>
        </nav>
        <div class="user-info">
            <div class="user-operate">
                <div class="user-one">
                    <div class="user-name">
                        <span id="username"></span>
                        <svg t="1687403727017" class="icon-user" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="872" width="15" height="15"><path d="M468.7872 738.5088c0-10.4448 4.096-20.8896 12.0832-28.8768L929.792 260.7104c15.9744-15.9744 41.984-15.9744 57.9584 0 7.9872 7.9872 12.0832 18.432 12.0832 28.8768s-4.096 20.8896-12.0832 28.8768L538.624 767.3856c-15.9744 15.9744-41.984 15.9744-57.9584 0-7.9872-7.9872-11.8784-18.432-11.8784-28.8768z" p-id="873"></path><path d="M30.3104 260.9152c7.9872-7.9872 18.432-12.0832 28.8768-12.0832s20.8896 4.096 28.8768 12.0832l448.9216 448.9216c15.9744 15.9744 15.9744 41.984 0 57.9584-7.9872 7.9872-18.432 12.0832-28.8768 12.0832s-20.8896-4.096-29.0816-12.0832L30.3104 318.6688c-15.9744-15.9744-15.9744-41.7792 0-57.7536z" p-id="874"></path></svg>
                    </div>
                    <div class="user-links">
                        <ul>
                            <li><a href="/user"  target="_blank">个人中心</a></li>
                            <li><a href="/wallet"  target="_blank">我的钱包</a></li>
                            <li><a href="/order"  target="_blank">我的订单</a></li>
                            <li><a href="/uevaluate"  target="_blank">评论晒单</a></li>
                            <li><a href="/" onclick="ClearCookie()">退出登录</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <a href="/trolley" class="mini-shopping-cart">购物车(<span id="count-trolley">0</span>)</a>
        </div>
    </header>
    <main class="wallet">
        <div class="wallet-center">
            <div class="wallet-center-header">
                <h2>我的钱包</h2>
            </div>
            <div class="wallet-center-content">
                <div>
                    <h4>账户余额</h4>
                    <span>￥<span id="balance"></span></span>
                </div>
                <p data-toggle="modal" data-target="#updateBalance">
                    充值
                </p>
            </div>
        </div>
        <div class="wallet-record">
            <h4>交易记录</h4>
            <table role="walletrecord">
                <thead role="walletrecord">
                    <tr>
                        <th class="type">类型</th>
                        <th class="time">时间</th>
                        <th class="remark">备注</th>
                        <th class="price">金额</th>
                    </tr>
                </thead>
                <tbody role="walletrecord" id="record-tbody">
                    
                </tbody>
            </table>
        </div>
    </main>
    <div class="bottom">
        <div class="footer-links clearfix">
            <dl class="col-links col-links-first">
                <dt></dt>
            </dl>
            <dl class="col-links ">
                <dt>选购指南</dt>
                <dd><a rel="nofollow" href="/allphone">手机</a></dd>
                <dd><a rel="nofollow" href="/allcomputer">电脑</a></dd>
            </dl>

            <dl class="col-links ">
                <dt>服务中心</dt>
                <dd><a rel="nofollow" onclick="openChat()" style="cursor: pointer">智能客服</a></dd>7
                <dd><a rel="nofollow" href="/order" target="_blank">订单查询</a></dd>
            </dl>

            <dl class="col-links ">
                <dt>关于</dt>
                <dd><a rel="nofollow" href="https://sugarscat.com" target="_blank">了解我们</a></dd>
            </dl>
        </div>
        <div class="site-info">
            <div class="logo ir"></div>
            <div class="info-text">
                <p class="sites">
                    <a rel="nofollow" href="/" target="_blank">维多购物平台</a>
                    <span class="sep">|</span>
                    <a rel="nofollow" href="/privacy" target="_blank"
                    >隐私政策</a
                    >
                </p>
                <p class="sites">
                    <a rel="nofollow" href="http://www.cca.org.cn/" target="_blank"
                    >中国消费者协会</a
                    >
                    <span class="sep">|</span>
                    <a rel="nofollow" href="http://www.bj315.org/" target="_blank"
                    >北京市消费者协会</a
                    >
                </p>
                <p>
                    &copy;2023-至今 版权所有 维多购物平台
                    <br />
                    本网站所列数据、图片，均来自互联网已公开信息，仅供交流学习！
                </p>
            </div>
        </div>
    </div>
    <!-- 更新余额 -->
    <div class="modal fade" id="updateBalance" tabindex="-1" role="dialog"   aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-body">
            <div class="modal-content balance">
                <div class="title">
                    <h4 id="myModalLabel">充值</h4>
                    <button class="modal-btn-close" type="button" data-dismiss="modal"   aria-hidden="true">&times;</button>
                </div>
                <div class="content">
                    <form role="form">
                        <label for="price1">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price1" value="1" checked="checked">
                            <span>￥1</span>
                        </label>
                        <label for="price5">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price5" value="5" checked="checked">
                            <span>￥5</span>
                        </label>
                        <label for="price10">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price10" value="10">
                            <span>￥10</span>
                        </label>
                        <label for="price50">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price50" value="50">
                            <span>￥50</span>
                        </label>
                        <label for="price100">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price100" value="100">
                            <span>￥100</span>
                        </label>
                        <label for="price500">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price500" value="500" >
                            <span>￥500</span>
                        </label>
                        <label for="price1000">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price1000" value="1000" >
                            <span>￥1000</span>
                        </label>
                        <label for="price5000">
                            <input class="radio choicePrice" type="radio" name="choicePrice" id="price5000" value="5000">
                            <span>￥5000</span>
                        </label>
                    </form>
                </div>
                <div class="operate">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary"   onclick="updateBalance()">支付</button>
                </div>
            </div><!--   /.modal-content -->
        </div><!-- /.modal -->
    </div>
</body>
<script src="./js/message.js"></script>
<script src="./js/chat.js"></script>
<script>
    let id = GetCookie("id")
    let token = GetCookie("token")
    if (token.length>0) {
        $.ajax({
            url:"/api/wallet",
            method:"post",
            data:{
                id: id,
                token: token
            },
            success(res){
                if(res.code===1001) {
                    document.getElementById("username").innerText = res.user
                    document.getElementById("balance").innerText = res.money
                    let trade = res.trade
                    let html="";
                    for(let i=0; i < trade.length; i++){
                        html += `<tr>
                            <td class="type">` + trade[i].type + `</td>
                            <td class="time">`+ new Date(trade[i].ttime).toLocaleDateString() +" " 
                                + new Date(trade[i].ttime).getHours() + ":"
            	            + new Date(trade[i].ttime).getMinutes() + ":" 
                            + new Date(trade[i].ttime).getSeconds() +`</td>
                            <td class="remark">`+ trade[i].remark +`</td>
                            <td class="money"><h4>`+ trade[i].tmoney +  `</h4><span>交易后余额：`
                            + trade[i].balance + `</span></td></tr>`
                    }
                    $("#record-tbody").append(html)
                } else {
                    AddMessage("warning", "用户令牌过期")
                    setTimeout(()=>{
                        location.href = "/account#login"
                    }, 500)
                }
            }
        })
    } else {
        AddMessage("error", "未登录")
        setTimeout(()=>{
            location.href = "/account#login"
        }, 500)
    }

    function updateBalance() {
        let id = GetCookie("id")
        let token = GetCookie("token")
        let moneyChoice = document.getElementsByClassName("choicePrice")
        let money = 0
        for (let i = 0; i < moneyChoice.length; i++) {
            const element = moneyChoice[i];
            if (element.checked) {
                money = element.value
                break
            }
        }
        $.ajax({
            url:"/api/walletadd",
            method:"post",
            data:{
                id: id,
                token: token,
                money: money
            },
            success(res){
                if(res.code === 1001) {
                    AddMessage("success", "充值成功")
                    setTimeout(()=>{
                        location.reload()
                    }, 500)
                } else if (res.code === 1002) {
                    AddMessage("warning", "余额大于 30000")
                } else {
                    AddMessage("warning", "用户令牌过期")
                    setTimeout(()=>{
                        location.href = "/account#login"
                    }, 500)
                }
            }
        })
    }
</script>
</html>